﻿Namespace Forms.List
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Public Class frmPeriodClassList
        Inherits frmBaseGrid

#Region "Designer"

        'Form overrides dispose to clean up the component list.
        <System.Diagnostics.DebuggerNonUserCode()> _
        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            Try
                If disposing AndAlso components IsNot Nothing Then
                    components.Dispose()
                End If
            Finally
                MyBase.Dispose(disposing)
            End Try
        End Sub

        Friend WithEvents UcListPeriodClass As ucPeriodClassList

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        <System.Diagnostics.DebuggerStepThrough()> _
        Private Sub InitializeComponent()
            Me.UcListPeriodClass = New IIC.ucPeriodClassList()
            Me.pnlGrid.SuspendLayout()
            Me.SuspendLayout()
            '
            'pnlGrid
            '
            Me.pnlGrid.Controls.Add(Me.UcListPeriodClass)
            Me.pnlGrid.Location = New System.Drawing.Point(0, 53)
            Me.pnlGrid.Size = New System.Drawing.Size(760, 389)
            '
            'UcListPeriodClass
            '
            Me.UcListPeriodClass.Dock = System.Windows.Forms.DockStyle.Fill
            Me.UcListPeriodClass.Location = New System.Drawing.Point(0, 0)
            Me.UcListPeriodClass.Name = "UcListPeriodClass"
            Me.UcListPeriodClass.Size = New System.Drawing.Size(760, 389)
            Me.UcListPeriodClass.TabIndex = 0
            '
            'frmPeriodClassList
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.ClientSize = New System.Drawing.Size(760, 442)
            Me.Name = "frmPeriodClassList"
            Me.ShowExcelButton = True
            Me.ShowSearch = True
            Me.Text = "Class List"
            Me.Controls.SetChildIndex(Me.pnlGrid, 0)
            Me.pnlGrid.ResumeLayout(False)
            Me.ResumeLayout(False)

        End Sub

#End Region

#Region "Standard Code"
        Private tsPeriodFilter As New ToolStripComboBox

        Private Sub frmPeriodClassList_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
           Handles Me.Load

            Dim tsProjectFilterSep As New ToolStripSeparator
            Dim tsProjectFilterLabel As New ToolStripLabel

            tsProjectFilterSep.Size = New Size(6, 25)
            tsProjectFilterLabel.Text = "Period:"
            tsProjectFilterLabel.AutoSize = True


            Dim ls As List(Of Period) = New PeriodDBMapper().findAll
            ls.Sort(Function(p1, p2) -1 * p1.PeriodDate.GetValueOrDefault.CompareTo(p2.PeriodDate.GetValueOrDefault))

            tsPeriodFilter.ComboBox.DataSource = ls
            tsPeriodFilter.ComboBox.DisplayMember = "PeriodDescription"
            tsPeriodFilter.ComboBox.ValueMember = "PeriodId"
            tsPeriodFilter.Size = New System.Drawing.Size(200, 22)
            If tsPeriodFilter.ComboBox.Items.Count > 0 Then
                tsPeriodFilter.ComboBox.SelectedValue = CType(tsPeriodFilter.ComboBox.Items(0), Period).PeriodId
            End If

            AddHandler tsPeriodFilter.SelectedIndexChanged, _
                AddressOf tsPeriodFilter_selectedChanged


            Me.tlStripList.Items.Add(tsProjectFilterSep)
            Me.tlStripList.Items.Add(tsProjectFilterLabel)
            Me.tlStripList.Items.Add(tsPeriodFilter)

            Me.filterPeriods()

        End Sub

        ''' <summary>
        ''' This function is common to all forms that inherit from class frmBaseGrid
        ''' It priovides a common name to the underlying grid control that shows the records
        ''' </summary>
        Public Overrides Function grdData() As org.codegen.win.controls.Grid.CGBaseGrid
            Return Me.UcListPeriodClass.grdPeriodClass
        End Function

        Protected Sub DeleteRecordConfirmed(ByVal sender As System.Object) Handles Me.gridDeleteRecordConfirmed

            Dim m As New PeriodClassDBMapper
            Dim mo As PeriodClass = m.findByKey(Me.grdData.IdValue)
            Call m.delete(mo)

        End Sub

        Private Sub tsPeriodFilter_selectedChanged(ByVal sender As Object, ByVal e As EventArgs)
            Call filterPeriods()
        End Sub

        Private Sub filterPeriods()

            Dim filterSQL As String = String.Empty
            If tsPeriodFilter.ComboBox.SelectedItem Is Nothing Then
                filterSQL = "1=0"
            Else
                Dim periodid As Integer = CType(tsPeriodFilter.ComboBox.SelectedItem, Period).PeriodId
                filterSQL = "PeriodId=" & periodid
            End If

            Me.UcListPeriodClass.grdPeriodClass.gpWhereclause = filterSQL
            Me.UcListPeriodClass.grdPeriodClass.loadGrid()


        End Sub

        Public Overrides Function PrepareEditForm(ByVal pkValue As Integer, ByVal editForm As frmBaseEdit) As Boolean

            If tsPeriodFilter.ComboBox.SelectedItem Is Nothing Then
                Call winUtils.MsgboxStop("Please select a period before adding a new Class.")
                Return False
            End If

            MyBase.PrepareEditForm(pkValue, editForm)

            Dim periodid As Integer = CType(tsPeriodFilter.ComboBox.SelectedItem, Period).PeriodId
            CType(editForm, Forms.Edit.frmPeriodClassDetails).UcPeriodClass.PeriodId.SelectedValue = periodid

            Return True

        End Function

#End Region

    End Class

End Namespace

